import type { App } from 'vue'
import { defineAsyncComponent } from "vue";
import type { AsyncComponentLoader } from "vue"; // vue3+ts+vite 加上type,不然会报错。
const componentss = import.meta.glob("@/components/common/*.vue");//全局这个无论多少层级
console.log(componentss)
console.log(Object.entries(componentss))
 
/**
 * 全局组件引用管理
 */
export default {
  install(app: App) {
    for (const [key, value] of Object.entries(componentss)) {
      // 字符串截取，具体看下面console.log()中的name就知道了
      const name = key.slice(key.lastIndexOf("/") + 1, key.lastIndexOf("."));
      console.log(name,value)

      app.component(name, defineAsyncComponent(value as AsyncComponentLoader));
    }      
  }
}